package com.admin.util;

import java.util.List;

public class PageBean<T> {
	
	private int pageSize = 15;			//默认设置每页显示数
	private int currentPage = 1;		//当前页
	private int start = 0;				//开始数
	private int totalCount = 0;			//总数
	private int totalPage = 1;			//总页数
	private boolean hasNext = false;	//是否有下一页
	private boolean hasPre = false;		//是否有上一页
	private String url = null;			//跳转地址
	private List<T> result = null;		//数据集合
	
	public PageBean(){
	}
	
	public PageBean(int totalCount,int currentPage){
		setTotalCount(totalCount);
		setCurrentPage(currentPage);
	}
	
	public PageBean(int totalCount,int currentPage,int pageSize){
		setPageSize(pageSize);
		setTotalCount(totalCount);
		setCurrentPage(currentPage);
	}

	public int getPageSize() {
		return pageSize;
	}

	private void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	private void setCurrentPage(int currentPage) {
		if(currentPage<1) currentPage = 1;
		if(currentPage>=totalPage) currentPage = totalPage;
		this.start = (currentPage - 1)*pageSize;
		this.currentPage = currentPage;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		if(start < 0 || start > totalCount) start = 0;
		this.start = start;
	}

	public int getTotalCount() {
		return totalCount;
	}

	private void setTotalCount(int totalCount) {
		int count = totalCount/pageSize;
		this.totalPage = totalCount%pageSize==0?count:(count+1);
		if(this.totalPage==0)this.totalPage=1;
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public boolean isHasNext() {
		this.hasNext = this.currentPage < this.totalPage?true:false; 
		return hasNext;
	}

	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}

	public boolean isHasPre() {
		this.hasPre = this.currentPage >1?true:false; 
		return hasPre;
	}

	public void setHasPre(boolean hasPre) {
		this.hasPre = hasPre;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}
}
